package leetcode;

import org.junit.Test;

/**
 * @author: feiwang_6
 * @create: 2020/4/18 14:38
 * @description:
 */
public class Regular {
    @Test
    public void testMath(){
        System.out.println(isMatch("mississippi", "mis*is*ip*."));
    }
    
    public boolean isMatch(String s, String p){
        if(p.isEmpty()){
            return s.isEmpty();
        }
        boolean first = !s.isEmpty() && (s.charAt(0) == p.charAt(0) || p.charAt(0) == '.');
        if(p.length() >= 2 && p.charAt(1) == '*'){
            return (first && isMatch(s.substring(1), p)) || isMatch(s, p.substring(2));
/*            if(first){
                return isMatch(s.substring(1), p);
            }else {
                return isMatch(s, p.substring(2));
            }*/
        }else {
            return first && isMatch(s.substring(1), p.substring(1));      
        }
    }
}
